import axios from 'axios';

class request {
    constructor() {
        const service = axios.create({
            // 基础配置：baseURL, timeout 等
            baseURL: process.env.VUE_APP_API_URL,
            timeout: 240000,
        });

        // 请求拦截器
        service.interceptors.request.use(
            (config) => {
                return config;
            },
            (error) => {
                // 处理请求错误
                return Promise.reject(error);
            }
        );

        // 响应拦截器
        service.interceptors.response.use(
            (response) => {
                // 在这里处理响应数据
                return response;
            },
            (error) => {
                // 处理响应错误
                return Promise.reject(error);
            }
        );

        this.service = service;
    }

    get(path, params) {
        return this.service.get(path, { params });
    }
    post(path, payload) {
        return this.service.post(path, payload);
    }

}

export default new request();
